﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ExtBusiness.FlowOperation;
using ExtBusiness;
using ExtBusiness.User;
using ExtBusiness.Admin;

public partial class Xnjc_Bjdb : PageBase
{
    public String tag1 = string.Empty;
    public String tag2 = string.Empty;
    public String tag3 = string.Empty;
    //定义分页变量
    public int pagesize = 15;//页面记录数
    public int pagenow = 1;//当前页
    public String mpage = string.Empty;

    public String s_worktype = string.Empty;
    public String d_s = string.Empty;
    public String d_e = string.Empty;
    public String type = string.Empty;
    public String s_ck1 = string.Empty;
    public String s_ck2 = string.Empty;
    public String s_ck3 = string.Empty;
    public string userid = string.Empty;
    public DataTable dtSource;
    public ClsWorkFlow clsWorkFlow = new ClsWorkFlow();
    public string strhtml1 = string.Empty;
    public string strhtml2 = string.Empty;
    protected ExtBusiness.Controls.Pager mypage ;
    protected int pagecount = 0;

    protected void Page_Load(object sender, System.EventArgs e)
    {

        mpage = Request["pagenow"];

        if (!string.IsNullOrEmpty(mpage))
        {
            pagenow = Int32.Parse(mpage); ;
            if (pagenow < 1)
                pagenow = 1;
        }
        else
        {
            pagenow = 1;
        }

         s_worktype = Request["s_worktype"];
         d_s = Request["Date_begin"];
         d_e = Request["Date_end"];
         type = Request["st_lctype"];
         s_ck1 = Request["checkbox1"];
         s_ck2 = Request["checkbox2"];
         s_ck3 = Request["checkbox3"];

        if (string.IsNullOrEmpty(d_s))
        {
            d_s = string.Empty;
        }
        if (string.IsNullOrEmpty(d_e))
        {
            d_e = string.Empty;
        }

        if (string.IsNullOrEmpty(s_ck1) || s_ck1.Equals("false"))
        {
            s_ck1 = string.Empty;
        }
        else
        {
            tag1 = "checked";
        }
        if (string.IsNullOrEmpty(s_ck2) || s_ck2.Equals("false"))
        {
            s_ck2 = string.Empty;
        }
        else
        {
            tag2 = "checked";
        }
        if (string.IsNullOrEmpty(s_ck3) || s_ck3.Equals("false"))
        {
            s_ck3 = string.Empty;
        }
        else
        {
            tag3 = "checked";
        }
        if (string.IsNullOrEmpty(type))
        {
            type = "2";
        }
        if (string.IsNullOrEmpty(s_worktype))
        {
            s_worktype = "1";
        }

         userid = UserId;
         ClsWorkFlow clsWorkFlow = new ClsWorkFlow();
         dtSource = clsWorkFlow.GetFlowNameByUserID(userid);

         if (s_worktype.Equals("1"))
         {
             strhtml1+="<option value= 1 SELECTED>所有类型</option>" + "\r\n";
         }
         else
         {
             strhtml1+="<option value= 1 >所有类型</option>" + "\r\n";
         }

         foreach (System.Data.DataRow drSource in dtSource.Rows)
         {
             String name = drSource[0].ToString();

             if (s_worktype.Equals(name))
             {
                 strhtml1+="<option value=\"" + name + "\" selected>" + name + "</option>" + "\r\n";
             }
             else
             {
                 strhtml1+="<option value=\"" + name + "\" >" + name + "</option>" + "\r\n";
             }
         }

         String ZGTimeout = string.Empty;
         String GWTimeout = string.Empty;
         String strGq = string.Empty;

         int k = 0;
         int j = 0;
         int y = 0;

         if (!string.IsNullOrEmpty(s_ck1))//业务超时
         {
             ZGTimeout = "超时";
             k = 1;
         }
         if (!string.IsNullOrEmpty(s_ck2))//岗位超时
         {
             GWTimeout = "超时";
             j = 1;
         }
         if (!string.IsNullOrEmpty(s_ck3))
         {
             strGq = "挂起";
             y = 1;
         }
         System.Data.DataTable dtSerial = clsWorkFlow.GetAllInstanceInfo(k, j, y, s_worktype, d_s, d_e, type, userid);
          mypage = new ExtBusiness.Controls.Pager(dtSerial, pagenow, pagesize);

          pagecount = mypage.PageCount;
         System.Collections.Generic.List<System.Data.DataRow> listwork = mypage.CurrentPageList;

         foreach (System.Data.DataRow myArray in listwork)
         {
             //把业务类型号转换成名字
             String LcName = myArray[0].ToString();

             string strFlowName = clsWorkFlow.GetFlowName(LcName);

             if (!string.IsNullOrEmpty(strFlowName))
             {
                 LcName = strFlowName;
             }

             //查找在办节点
             String s_iid = myArray[1].ToString();
             String s_username = string.Empty;

             //查找在办人
             string[] arrStrReturn = clsWorkFlow.FindSerialOnPeople(s_iid);

             if (!string.IsNullOrEmpty(arrStrReturn[0]))
             {
                 s_iid = arrStrReturn[0];
                 s_username = arrStrReturn[1];
             }

             ExtBusiness.Struct.UserStruct userInfo = ExtBusiness.Admin.User.GetUserById(s_username);
             if (!string.IsNullOrEmpty(userInfo.UserRealName))
             {
                 s_username = userInfo.UserRealName;
             }
             else
             {
                 s_username = "&nbsp";
             }

             //是否整超时
             if (string.IsNullOrEmpty(ZGTimeout))
             {
                 if (s_iid.Equals("1"))
                 {
                     ZGTimeout = "超时";
                 }
             }

             //是否岗位超时
             if (string.IsNullOrEmpty(GWTimeout))
             {
                 if (s_iid.Equals("2"))
                 {
                     GWTimeout = "超时";
                 }
             }

             //是否挂起
             if (string.IsNullOrEmpty(strGq))
             {
                 if (s_iid.Equals("2"))
                 {
                     strGq = "挂起";
                 }
             }

             string strLimiteTime = myArray[4].ToString();
             string strHaveUseTime = myArray[5].ToString();

             if (!string.IsNullOrEmpty(strLimiteTime))
             {
                 double dLimiteTime = Convert.ToDouble(myArray[4]);
                 if (dLimiteTime != 0.0)
                 {
                     strLimiteTime = ClsWorkDaySet.ToDefaultTime(dLimiteTime);
                 }
                 else
                 {
                     strLimiteTime = "0天0小时0分钟";
                 }
             }

             if (!string.IsNullOrEmpty(strHaveUseTime))
             {
                 double dHaveUseTime = Convert.ToDouble(myArray[5]);
                 if (dHaveUseTime != 0.0)
                 {
                     strHaveUseTime = ClsWorkDaySet.ToDefaultTime(dHaveUseTime);
                 }
                 else
                 {
                     strHaveUseTime = "0天0小时0分钟";
                 }
             }

             strhtml2+="<tr bgcolor=\"#ffffff\" onmouseover=\"this.style.backgroundColor='#caf7fd'\" onMouseOut=\"this.style.backgroundColor='#ffffff'\">" + "\r\n";
             strhtml2+="<td align=\"center\">" + myArray[1].ToString() + "</td>" + "\r\n";
             strhtml2+="<td align=\"center\">" + LcName + "</td>" + "\r\n";
             strhtml2+="<td align=\"center\">" + myArray[2].ToString() + "</td>" + "\r\n";
             strhtml2+="<td  >" + myArray[3].ToString() + "</td>" + "\r\n";
             strhtml2+="<td  >" + s_iid + "</td>" + "\r\n";
             strhtml2+="<td  >" + s_username + "</td>" + "\r\n";

             if (strLimiteTime.Equals("0天0小时0分钟"))
                 strLimiteTime = "无";
             strhtml2+="<td  >" + strLimiteTime + "</td>" + "\r\n";

             strhtml2+="<td  >" + strHaveUseTime + "</td>" + "\r\n";
             strhtml2+="<td  >" + ZGTimeout + "</td>" + "\r\n";
             strhtml2+="<td  >" + GWTimeout + "</td>" + "\r\n";
             strhtml2+="<td  >" + strGq + "</td>" + "\r\n";
             strhtml2+="<td >" + "<a href=\"InsUrgeDetail.aspx?id=" + myArray[1].ToString()
                 + "&pagenow=" + pagenow + "&s_worktype=" + LcName + "&Date_begin=" + d_s + "&Date_end="
                 + d_e + "&s_lctype=" + type + "&checkbox1=" + s_ck1 + "&checkbox2=" + s_ck2 + "&checkbox3="
                 + s_ck3 + "&s_worktype1=" + s_worktype + "\" target=\"_self\">详细信息</a>" + "</td>"
                 + "\r\n";
             strhtml2+="</tr>" + "\r\n";
         }
	
	

    }
}
